<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['role']=$_SESSION['role'];
if($_RQ['op']=='main'){
	$member=cfc('core')->member_show($_SESSION['uid']);
	$mymember=pdo_get('jy_nongfee_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$member=array_merge($member,$mymember);
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$member['quan0']=$this->getsum('quanlog',array('type'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'num');
	$member['quan1']=$this->getsum('quanlog',array('type'=>1,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'num');
	$member['quanfee']=$this->getsum('quanlog',array('type'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'fee');
	$return['member']=$member;
	$return['list']=array();
	set_html('title','我的种植券');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_nongfee_quanlog',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($return['list'] as &$v){
			$teampaixu=pdo_getcolumn('jy_nongfee_cang',array('id'=>$v['cangid'],'uniacid'=>$_SESSION['uniacid']),'paixu');
			$yaopaixu=pdo_getcolumn('jy_nongfee_yao',array('id'=>$v['yaoid'],'uniacid'=>$_SESSION['uniacid']),'paixu');
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
			$v['typetitle']=$this->quan_types[$v['type']];
			$v['title']='第'.$teampaixu.'庄园第'.$yaopaixu.''.$this->y_title;
	}
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['fee']){
		exi('请选择兑换套餐！','erroe');
	}
	$item=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
	if($item['credit1']<$post['fee']){
		exi('当前剩余积分只有'.$item['credit1'].'个！不能兑换该套餐！','error');
	}
	model('core/member')->member_credit($_SESSION['uid'],'credit1',$post['fee'],false,'jy_nongfee','积分兑换种植券','zquan');
	pdo_update('jy_nongfee_member',array('zquan +='=>intval($post['num'])),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('兑换成功！');
}